create or replace function posterminalConnectionTypeSave(
	out xml, inout xml
	)
as
$$
	declare
		executeStatusData alias for $1;
		posterminalConnectionTypeData alias for $2;
		vIdPosterminalConnectionType integer := null;
		vNamePosterminalConnectionType text := null;
		vIdNode varchar(100) := '/posterminalconnectiontype/@id';
		vNamePosterminalConnectionTypeNode varchar(100) := '/posterminalconnectiontype/posterminalconnectiontypename';
	begin
		vIdPosterminalConnectionType := cast(extract_value(vIdNode, posterminalConnectionTypeData) as integer);
		vNamePosterminalConnectionType := extract_value(vNamePosterminalConnectionTypeNode, posterminalConnectionTypeData);
		if (vIdPosterminalConnectionType = null or vIdposterminalConnectionType = noId()) then begin
			insert into posterminalconnectiontype(namePosterminalConnectionType) values(vNamePosterminalConnectionType) 
				returning idPostermialConnectionType into vIdPosterminalConnectionType;
			posterminalConnectionTypeData := posterminalConnectionTypeData2Xml(vIdPosterminalConnectionTypeData, vNamePosterminalConnectionTypeData);
			executeStatusData := statusCall(successcode(), 'Inserted');
			return;
		end;
		else begin
			update posterminalconnectiontype
				set nameposterminalconnectiontype = vNamePosterminalConnectionType
				where
					idposterminalconnectiontype = vIdPosterminalConnetionType;
			executeStatusData := statusCall(successcode(), 'Updated');
		end;
		end if;
	end;
$$ language plpgsql VOLATILE;